#include <iostream>
#include <memory>

using std::cout;
using std::endl;
using std::auto_ptr;

void test()
{
    //裸指针
    int *pInt = new int(10);
    /* auto_ptr<int> ap(new int(10)); */
    //智能指针
    auto_ptr<int> ap(pInt);
    cout << "*ap = " << *ap << endl;
    cout << "*pInt = " << *pInt << endl;
    cout << "ap.get() = " << ap.get() << endl;
    cout << "pInt = " << pInt << endl;

    cout << endl << endl;
    //auto_ptr在进行复制或者赋值的时候，底层的控制权发生了
    //转移，并且将ap底层的指为了空，所以该智能指针在使用上
    //存在缺陷
    auto_ptr<int> ap2(ap);//复制
    cout << "*ap2 = " << *ap2 << endl;
    cout << "ap2.get() = " << ap2.get() << endl;
    cout << "*ap = " << *ap << endl;//出问题了
    cout << "ap.get() = " << ap.get() << endl;
}

int main(int argc, char *argv[])
{
    test();
    return 0;
}

